//
//  HHTextEditorSample.swift
//  HHSwiftuiPractice
//
//  Created by YL-Hong on 2023/10/8.
// TextEditor 是用于编辑和显示多行文本的组件

import SwiftUI

struct HHTextEditorSample: View {
    
    @State var textEditorText: String = "666"
    @State var resultText: String = ""
    var color = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
    var body: some View {
        NavigationView {
           VStack {
               TextEditor(text: $textEditorText)
                   .foregroundColor(.black)
                   .multilineTextAlignment(.leading)
                   .frame(height: 240)
                   .colorMultiply(Color(uiColor: color))
                   .cornerRadius(10)
               
               Button {
                   resultText = textEditorText
               } label: {
                   Text("Save".uppercased())
                       .foregroundColor(.white)
                       .font(.headline)
                       .frame(maxWidth: .infinity)
                       .padding()
                       .background(Color.blue.cornerRadius(10))
               }
               
               Text(resultText)
               Spacer()
           }
           .padding(.horizontal)
           .navigationTitle("TextEditor sample")
       }
    }
}

struct HHTextEditorSample_Previews: PreviewProvider {
    static var previews: some View {
        HHTextEditorSample()
    }
}
